package org.langqiao.network.socket;
import  javax.swing.*;
import java.io.*;
import java.net.*;
public class ReceiveCardJFrame extends JFrame {//接收客户端程序
	public ReceiveCardJFrame(String name,String host,int port)throws IOException
	{
		super(name+"	"+InetAddress.getLocalHost());
		this.setBounds(320,240,320,80);
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		JTextArea text=new JTextArea();
		this.getContentPane().add(text);//在窗口框架中添加text文本区域
		this.setVisible(true);
		Socket socket=new Socket(host,port);
		this.setTitle(this.getTitle()+":"+socket.getLocalPort());//框架标题栏添加端口
		DataInputStream din=new DataInputStream(socket.getInputStream());//获得socket输入流
		while(true)//输入流未结束
		try
		{
			text.append(din.readInt()+" ");//从输入流读取一个整数并显示
		}
		catch(EOFException e)
		{
			break;
		}
		din.close();//关闭数据流
		socket.close();//关闭socket连接
			
	}
	public static void main(String[] args)throws IOException
	{
		new ReceiveCardJFrame("东","127.0.0.1",2001);
		/*new ReceiveCardJFrame("南","127.0.0.1",2002);
		new ReceiveCardJFrame("西","127.0.0.`",2003);
		new ReceiveCardJFrame("北","127.0.0.1",2004);*/
	}

}
